package com.hjwoo.app.common;

import android.app.Application;
import android.content.Context;
import android.os.Handler;

import com.hjwoo.app.fragment.UserCenterFragment;

import org.xutils.BuildConfig;
import org.xutils.x;

/**
 * Created by zhaokaiwen on 2016/4/26.
 */
public class LoanApplication extends Application
{

    public static  Context         context;
    private static LoanApplication app;
    /**
     * 共享变量
     */
    private UserCenterFragment.MyUserCenterHandler myUserCenterHandler = null;

    public LoanApplication()
    {
        app = this;
    }

    public static Context getContext()
    {
        if (context != null)
        {
            return context;
        }
        return app.getApplicationContext();
    }

    /**
     * 获取app实例
     *
     * @return
     */
    public static synchronized LoanApplication getInstance()

    {
        if (app == null)
        {
            app = new LoanApplication();
        }
        return app;
    }

    // get方法
    public Handler getHandler()
    {
        return myUserCenterHandler;
    }

    // set方法
    public void setHandler(UserCenterFragment.MyUserCenterHandler myUserCenterHandler)
    {
        this.myUserCenterHandler = myUserCenterHandler;
    }

    @Override
    public void onCreate()
    {
        super.onCreate();
        context = getApplicationContext();
        x.Ext.init(this);//Xutils初始化
        x.Ext.setDebug(BuildConfig.DEBUG); // 开启debug会影响性能
    }

//    // 注册App异常崩溃处理器
//    private void registerUncaughtExceptionHandler() {
//        Thread.setDefaultUncaughtExceptionHandler(AppException.getAppExceptionHandler());
//    }
}
